package com.sunshine.domain.service.impl;

import com.sunshine.domain.convert.SubjectCategroyConvert;
import com.sunshine.domain.entity.SubjectCategroyBO;
import com.sunshine.domain.service.SubjectCategoryDomainService;
import com.sunshine.infra.basic.entity.SubjectCategory;
import com.sunshine.infra.basic.service.SubjectCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 题目分类服务实现类
 * @version 1.0
 * @Author 夏百友
 * @Date 2025/10/31 23:47
 */

@Slf4j
@Service
public class SubjectCategoryServiceImpl implements SubjectCategoryDomainService {


    @Resource
    private SubjectCategoryService subjectCategoryService;
    @Override
    public void addSubjectCategory(SubjectCategroyBO subjectCategorybo) {

        SubjectCategory subjectCategory = SubjectCategroyConvert.INSTANCE.convertBoToCategory(subjectCategorybo);

        subjectCategoryService.insert(subjectCategory);

        log.info("domain.service.SubjectCategoryDomainService添加结果:{}",subjectCategory);


    }

    @Override
    public List<SubjectCategroyBO> queryPrimaryCategory(SubjectCategroyBO subjectCategroyBO) {

        if (log.isInfoEnabled()){
            log.info("domain.service.SubjectCategoryDomainService.queryPrimaryCategory:参数{}", subjectCategroyBO);
        }
        List<SubjectCategory> subjectCategoryList = subjectCategoryService.queryAll(SubjectCategroyConvert.INSTANCE.convertBoToCategory(subjectCategroyBO));

        if (log.isInfoEnabled()){
            log.info("domain.service.SubjectCategoryDomainService.queryPrimaryCategory:查询结果{}", subjectCategoryList);
        }

        return SubjectCategroyConvert.INSTANCE.convertCategoryBoToDtoList(subjectCategoryList);
    }

    @Override
    public Boolean update(SubjectCategroyBO subjectCategoryBO) {
        if (log.isInfoEnabled()){
            log.info("domain.service.SubjectCategoryDomainService.update:参数{}", subjectCategoryBO);
        }
        Date date = new Date();

        int count = subjectCategoryService.update(SubjectCategroyConvert.INSTANCE.convertBoToCategory(subjectCategoryBO));
        log.info("domain.service.SubjectCategoryDomainService.update:结果{}", subjectCategoryBO);
        return  count > 0;
    }

    @Override
    public Boolean deleteCategory(SubjectCategroyBO subjectCategoryBO) {

        if (log.isInfoEnabled()){
            log.info("domain.service.SubjectCategoryDomainService.deleteCategory:参数{}", subjectCategoryBO);
        }
        boolean b = subjectCategoryService.deleteById(subjectCategoryBO.getId());
        log.info("domain.service.SubjectCategoryDomainService.deleteCategory:结果{}", b);
        return b;
    }
}
